package com.fxbin123.handler;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

/**
 * created with IntelliJ IDEA.
 * author: fxbin
 * date: 2018/7/15
 * time: 19:21
 * description:
 */
@Component
public class EchoHandler implements WebSocketHandler {
    @Override
    public Mono<Void> handle(final WebSocketSession webSocketSession) {
        return webSocketSession.send(
                webSocketSession.receive()
                .map(msg -> webSocketSession.textMessage(
                        "服务端返回： 小明， --->>> " + msg.getPayloadAsText())));
    }
}
